package com.ruoyi.history.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.history.domain.LiveHistory;
import com.ruoyi.history.service.ILiveHistoryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 历史直播数据管理Controller
 * 
 * @author ruoyi
 * @date 2023-04-07
 */
@Controller
@RequestMapping("/history/history")
public class LiveHistoryController extends BaseController
{
    private String prefix = "history/history";

    @Autowired
    private ILiveHistoryService liveHistoryService;

    @RequiresPermissions("history:history:view")
    @GetMapping()
    public String history()
    {
        return prefix + "/history";
    }

    /**
     * 查询历史直播数据管理列表
     */
    @RequiresPermissions("history:history:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LiveHistory liveHistory)
    {
        startPage();
        List<LiveHistory> list = liveHistoryService.selectLiveHistoryList(liveHistory);
        return getDataTable(list);
    }

    /**
     * 导出历史直播数据管理列表
     */
    @RequiresPermissions("history:history:export")
    @Log(title = "历史直播数据管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LiveHistory liveHistory)
    {
        List<LiveHistory> list = liveHistoryService.selectLiveHistoryList(liveHistory);
        ExcelUtil<LiveHistory> util = new ExcelUtil<LiveHistory>(LiveHistory.class);
        return util.exportExcel(list, "历史直播数据管理数据");
    }

    /**
     * 新增历史直播数据管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存历史直播数据管理
     */
    @RequiresPermissions("history:history:add")
    @Log(title = "历史直播数据管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LiveHistory liveHistory)
    {
        return toAjax(liveHistoryService.insertLiveHistory(liveHistory));
    }

    /**
     * 修改历史直播数据管理
     */
    @RequiresPermissions("history:history:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        LiveHistory liveHistory = liveHistoryService.selectLiveHistoryById(id);
        mmap.put("liveHistory", liveHistory);
        return prefix + "/edit";
    }

    /**
     * 修改保存历史直播数据管理
     */
    @RequiresPermissions("history:history:edit")
    @Log(title = "历史直播数据管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LiveHistory liveHistory)
    {
        return toAjax(liveHistoryService.updateLiveHistory(liveHistory));
    }

    /**
     * 删除历史直播数据管理
     */
    @RequiresPermissions("history:history:remove")
    @Log(title = "历史直播数据管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(liveHistoryService.deleteLiveHistoryByIds(ids));
    }
}
